home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!news
- From: miker3@ix.netcom.com (Mike Rubenstein)
- Newsgroups: comp.lang.c++
- Subject: Re: Derivation and calling virtual functions
- Date: Fri, 29 Mar 1996 13:19:16 GMT
- Organization: Netcom
- Message-ID: <315be2ff.257321608@nntp.ix.netcom.com>
- References: <graphix.828032689@spiff.cc.iastate.edu>
- NNTP-Posting-Host: ix-dc11-06.ix.netcom.com
- X-NETCOM-Date: Fri Mar 29 7:16:11 AM CST 1996
- X-Newsreader: Forte Agent .99d/32.182
-
- graphix@iastate.edu (Kent A Vander Velden) wrote:
-
- > Say we have the following:
- >
- > class Base {
- > public:
- > virtual void func() { // some stuff }
- > virtual void write() { func(); };
- > };
- >
- > class Derived : public Base {
- > public:
- > void func() { // some stuff }
- > write(); { Base::func(); }
- > };
- >
- > Derived inst;
- >
- > Now, when I call inst.write() it in turn calls Bass::write() which in
- > turn calls Base::func(). Is there a way to instead have it call
- > Derived::func() if the instance is of type Derived? I hoped the
- > virtual keyword would help in this case.
-
- The virtual keyword should do it. This is it's purpose.
-
-
- Michael M Rubenstein
-